package com.sunbim.rsrv.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.io.File;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    // 静态目录地址,如果使用绝对路径, 则在配置文件中写入路径,然后通过@Value注解拿到值
    // System.getProperty("user.dir") 在开发时是项目根路径,即pom.xml所在目录,部署后是jar包的所在目录
    private final String staticPathRoot = System.getProperty("user.dir") + File.separator + "static/";

    @Value("${staticServer.uri}")
    private String uri;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler(uri).addResourceLocations("file:" + staticPathRoot);
    }
}
